package com.onlyMe.world.components.grababble
{
	import com.onlyMe.world.components.base.BaseIsleComponent;
	import com.onlyMe.world.components.inventory.InventoryComponent;
	import com.onlyMe.world.objects.IsleObjectContext;
	import com.onlyMe.world.objects.IsleObjectEvent;
	
	/**
	 * @author ariel
	 * 
	 * @requiresComponent InventoryComponent
	 */
	public class GrababbleComponent extends BaseIsleComponent
	{
		private var _weight:Number;
		private var grabbed:Boolean;
		
		public function GrababbleComponent()
		{
		}
		
		//-- Deserialization
		
		override public function deserialize(xml:XML):void
		{
			super.deserialize(xml);
			_weight = xml.@weight;
		}
		
		//-- Exposed properties
		
		public function get weight():Number
		{
			return _weight;
		}
		
		//-- Event handlers
		
		private function grabFromEvent(e:IsleObjectEvent):void
		{
			object.context = e.other.getByType(InventoryComponent) as InventoryComponent;
		}

		//-- Component
		
		override public function initialize():void
		{
			super.initialize();
			object.addEventListener(IsleObjectEvent.ACTIVATED_IN_ISLE, grabFromEvent);
		}
		
		override public function unregister():void
		{
			super.unregister();
			object.removeEventListener(IsleObjectEvent.ACTIVATED_IN_ISLE, grabFromEvent);
		}
	}

}
